package com.lzx.applib.listener;

import android.media.MediaPlayer;
import android.media.MediaPlayer.*;

import com.lzx.applib.utils.LogUtil;

/**
 * Created by Lzx on 16/11/18 0018.
 */
public interface MediaListener extends OnBufferingUpdateListener,
        OnErrorListener, OnCompletionListener, OnPreparedListener,
        OnInfoListener, OnSeekCompleteListener, OnVideoSizeChangedListener {

    public class MediaListenerAdapter implements OnBufferingUpdateListener,
            OnErrorListener, OnCompletionListener, OnPreparedListener,
            OnInfoListener, OnSeekCompleteListener, OnVideoSizeChangedListener {

        public static final String TAG = "VideoListener";

        @Override
        public void onBufferingUpdate(MediaPlayer mp, int percent) {
            LogUtil.d(TAG, "onBufferingUpdate", percent);
        }

        @Override
        public boolean onError(MediaPlayer mp, int what, int extra) {
            LogUtil.d(TAG, "onError", what, extra);
            return false;
        }

        @Override
        public void onCompletion(MediaPlayer mp) {
            LogUtil.d(TAG, "onCompletion");
        }

        @Override
        public boolean onInfo(MediaPlayer mp, int what, int extra) {
            LogUtil.d(TAG, "onInfo() called with:", what, extra);
            switch (what) {
                case MediaPlayer.MEDIA_INFO_BUFFERING_START:
                    showVideoBuffering(true);
                    break;
                case MediaPlayer.MEDIA_INFO_BUFFERING_END:
                    showVideoBuffering(false);
                    break;
                default:
                    showVideoBuffering(false);
                    break;
            }
            return false;
        }

        @Override
        public void onPrepared(MediaPlayer mp) {
            LogUtil.d(TAG, "onPrepared");
            mp.setOnBufferingUpdateListener(this);
            mp.setOnSeekCompleteListener(this);
            mp.setOnInfoListener(this);
            mp.setOnVideoSizeChangedListener(this);
            showVideoBuffering(false);
        }

        @Override
        public void onSeekComplete(MediaPlayer mp) {
            LogUtil.d(TAG, "onSeekComplete");
        }

        @Override
        public void onVideoSizeChanged(MediaPlayer mp, int width, int height) {
            LogUtil.d(TAG, "onVideoSizeChanged", width, height);
        }

        public void showVideoBuffering(boolean buffering) {

        }
    }

}
